import React from "react";
// useSelector是用于获取仓库数据
// useDispatch用来获得仓库的方法
import { useSelector, useDispatch } from "react-redux";

const App = () => {
  // useSelector里面传入一个回调函数，并且这个回调函数有一个state参数
  const count = useSelector((state) => state.count);
  // useDispatch直接调用返回dispatch对象
  const dispatch = useDispatch();

  return (
    <>
      <h2>redux-hooks</h2>
      <button onClick={() => dispatch({ type: "decrement" })}>-</button>
      <span>{count}</span>
      <button onClick={() => dispatch({ type: "increment", num: 3 })}>+</button>
    </>
  );
};

export default App;
